import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;



import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import io.appium.java_client.android.AndroidDriver;

import java.io.File;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
 * Created by CNJECHE11 on 2017/4/20.
 */
public class wapp {
    private  AndroidDriver  driver;
    @BeforeTest
    public void setUp() throws Exception {
        // set up appium
       /* File classpathRoot = new File(System.getProperty("user.dir"));
        File appDir = new File(classpathRoot, "apps");
        File app = new File(appDir, "zhihu.apk");*/
        DesiredCapabilities capabilities = new DesiredCapabilities();
       // capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
        capabilities.setCapability("platformName", "Android");
     //   capabilities.setCapability("deviceName","211a6082");//小米3
     //   capabilities.setCapability("deviceName","33000eb82eed62ff");//三星平板 SM-T705C 01
        capabilities.setCapability("deviceName","c1a73138");                //小米4
       // capabilities.setCapability("platformVersion", "4.1.1");        //真机的Android版本
      //  capabilities.setCapability("udid","c1a73138");                //物理机ID
        capabilities.setCapability("platformVersion", "6.0.1");
        capabilities.setCapability("noReset","true");//不要每次重装APP
        //if no need install don't add this
      //  capabilities.setCapability("app", app.getAbsolutePath());

        //support Chinese
     //   capabilities.setCapability("unicodeKeyboard" ,"True");
      //  capabilities.setCapability("resetKeyboard", "True");
        //no need sign
    //    capabilities.setCapability("noSign", "True");

        capabilities.setCapability("appPackage", "com.abb.welcome");
        capabilities.setCapability("appActivity", "de.buschjaeger.welcome_ispf.BuschJaegerLauncherActivity");
      //  capabilities.setCapability("appPackage", "com.android.calculator2");
      //  capabilities.setCapability("appActivity",".Calculator");
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    }
    @AfterMethod(alwaysRun=true)
    public void tearDown() throws Exception {
        driver.quit();
    }

    @Test//(invocationCount=1)
    public void Login() throws InterruptedException {
        //find login button
        Thread.sleep(3000);
        List<WebElement> loginButton = driver.findElements(By.className("android.widget.RelativeLayout"));
        loginButton.get(1).click();
        Thread.sleep(5000);
        //Assert.assertTrue(driver.findElement(By.id("com.abb.welcome:id/osname")).isDisplayed());
        Assert.assertTrue(driver.findElement(By.id("com.abb.welcome:id/cam_next")).isDisplayed());

        driver.findElement(By.id("com.abb.welcome:id/incallHang")).click();

        //wait for 20s
       /* driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

        //find login userName and password editText
        List<WebElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText");
        textFieldsList.get(0).sendKeys("seleniumcookies@126.com");
        textFieldsList.get(1).sendKeys("cookies123");
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

        //find ok button byName
        driver.findElementByName("OK").click();
        driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);

        //find keyword 首页 and verify it is display
        Assert.assertTrue( driver.findElement(By.name("首页")).isDisplayed());*/


    }
}
